package com.pptiku.jh.routerdemo;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebViewClient;

@Route(path = "/business/web")
public class WebViewActivity extends AppCompatActivity
{
    private X5WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        webView = findViewById(R.id.webview);

        String url = getIntent().getStringExtra("url");
        webView.clearCache(true);
        if (!TextUtils.isEmpty(url))
        {
            webView.loadUrl(url);
        }
        webView.setWebViewClient(new WebViewClient()
        {
            public boolean shouldOverrideUrlLoading(com.tencent.smtt.sdk.WebView view, String url)
            {
                if(!url.startsWith("k2://"))
                {
                    view.loadUrl(url);
                }else
                {
                    ARouter.getInstance().build(Uri.parse(url)).greenChannel().navigation();
                }
                return true;
            }
        });

        webView.setWebChromeClient(new WebChromeClient()
        {
        });

    }
}
